/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MatchFixtures.java
 *
 * Created on Jun 15, 2009, 5:58:16 AM
 */

package matpred;

import java.awt.Component;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Demola
 */
public class MatchFixtures extends javax.swing.JPanel {

    /** Creates new form MatchFixtures */
    public MatchFixtures() {
        initComponents();
        setTable();
        dtm.addRow(new Object[] {"", "", "","", "", "", new Object[] {"", "", "", "", "", "", "", "", "", "", "", "", ""},
                new Object[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"}});
    }
    
    public static MatchFixtures getMatchFixtures(){
        if(mfix == null){
            mfix = new MatchFixtures();
        }
        return mfix;
    }

    private void setTable(){
        ArrayList<String> columnNames = new ArrayList();
        columnNames.add("");
        columnNames.add("Date");
        columnNames.add("Fix No.");
        columnNames.add("Home Team");
        columnNames.add("Away Team");
        columnNames.add("Scores");
        columnNames.add("E's Fixture Number");
        columnNames.add("F's Fixture Number");

        dtm = new DefaultTableModel(new Object [][] {}, columnNames.toArray()){
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        jTable1.setModel(dtm);

        for(int i = 6; i < dtm.getColumnCount(); i++){
            jTable1.getColumnModel().getColumn(i).setCellRenderer(new MCellRenderer());
            jTable1.getColumnModel().getColumn(i).setMinWidth(250);
        }

        for(int i = 0; i < dtm.getColumnCount(); i++){
            jTable1.getColumnModel().getColumn(i).setResizable(false);

        }

//        return dtm;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jLabel1.setText("Generate Fixtures");

        jButton1.setText("Generate");

        jTable1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 923, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    private static MatchFixtures mfix;
    private DefaultTableModel dtm;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables


        class MCellRenderer implements TableCellRenderer{

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, final boolean isSelected, boolean hasFocus, int row, int column) {
            JTable cellTable = new JTable(new DefaultTableModel(new Object[][]{},
                    new Object[] {"", "", "", "", "", "", "", "", "", "", "", "", ""})){

                @Override
                public boolean isRowSelected(int row) {
                    return isSelected;
                }
            };
            cellTable.setTableHeader(null);
            DefaultTableModel dtm = (DefaultTableModel)cellTable.getModel();
            Object [] val = (Object[])value;
            dtm.addRow(val);
            return cellTable;
        }
    }
}
